/**
 * Copyright (C) 2022 Bonitasoft S.A.
 * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 **/
package org.bonitasoft.console.common.server.page;

import static java.lang.String.format;

import java.util.Locale;

import org.assertj.core.api.AbstractAssert;
import org.bonitasoft.console.common.server.page.extension.PageContextImpl;
import org.bonitasoft.engine.session.APISession;

/**
 * {@link PageContextImpl} specific assertions - Generated by CustomAssertionGenerator.
 */
public class PageContextAssert extends AbstractAssert<PageContextAssert, PageContextImpl> {

    /**
     * Creates a new </code>{@link PageContextAssert}</code> to make assertions on actual PageContext.
     *
     * @param actual the PageContext we want to make assertions on.
     */
    public PageContextAssert(PageContextImpl actual) {
        super(actual, PageContextAssert.class);
    }

    /**
     * An entry point for PageContextAssert to follow AssertJ standard <code>assertThat()</code> statements.<br>
     * With a static import, one's can write directly : <code>assertThat(myPageContext)</code> and get specific
     * assertion with code completion.
     *
     * @param actual the PageContext we want to make assertions on.
     * @return a new </code>{@link PageContextAssert}</code>
     */
    public static PageContextAssert assertThat(PageContextImpl actual) {
        return new PageContextAssert(actual);
    }

    /**
     * Verifies that the actual PageContext's apiSession is equal to the given one.
     *
     * @param apiSession the given apiSession to compare the actual PageContext's apiSession to.
     * @return this assertion object.
     * @throws AssertionError - if the actual PageContext's apiSession is not equal to the given one.
     */
    public PageContextAssert hasApiSession(APISession apiSession) {
        // check that actual PageContext we want to make assertions on is not null.
        isNotNull();

        // we overrides the default error message with a more explicit one
        String errorMessage = format("\nExpected <%s> apiSession to be:\n  <%s>\n but was:\n  <%s>", actual, apiSession,
                actual.getApiSession());

        // check
        if (!actual.getApiSession().equals(apiSession)) {
            throw new AssertionError(errorMessage);
        }

        // return the current assertion for method chaining
        return this;
    }

    /**
     * Verifies that the actual PageContext's locale is equal to the given one.
     *
     * @param locale the given locale to compare the actual PageContext's locale to.
     * @return this assertion object.
     * @throws AssertionError - if the actual PageContext's locale is not equal to the given one.
     */
    public PageContextAssert hasLocale(Locale locale) {
        // check that actual PageContext we want to make assertions on is not null.
        isNotNull();

        // we overrides the default error message with a more explicit one
        String errorMessage = format("\nExpected <%s> locale to be:\n  <%s>\n but was:\n  <%s>", actual, locale,
                actual.getLocale());

        // check
        if (!actual.getLocale().equals(locale)) {
            throw new AssertionError(errorMessage);
        }

        // return the current assertion for method chaining
        return this;
    }

    /**
     * Verifies that the actual PageContext's profileID is equal to the given one.
     *
     * @param profileID the given profileID to compare the actual PageContext's profileID to.
     * @return this assertion object.
     * @throws AssertionError - if the actual PageContext's profileID is not equal to the given one.
     */
    public PageContextAssert hasProfileID(String profileID) {
        // check that actual PageContext we want to make assertions on is not null.
        isNotNull();

        // we overrides the default error message with a more explicit one
        String errorMessage = format("\nExpected <%s> profileID to be:\n  <%s>\n but was:\n  <%s>", actual, profileID,
                actual.getProfileID());

        // check
        if (!actual.getProfileID().equals(profileID)) {
            throw new AssertionError(errorMessage);
        }

        // return the current assertion for method chaining
        return this;
    }

}
